package com.finer.service.impl;

import com.finer.dao.FinerSaleOrderDetailDao;
import com.finer.entity.sell.FinerSaleOrderDetail;
import com.finer.service.FinerSaleOrderDetailService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 销售订单详情表(FinerSaleOrderDetail)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:39
 */
@Service("finerSaleOrderDetailService")
public class FinerSaleOrderDetailServiceImpl implements FinerSaleOrderDetailService {
    @Resource
    private FinerSaleOrderDetailDao finerSaleOrderDetailDao;

    /**
     * 通过ID查询单条数据
     *
     * @param Id 主键
     * @return 实例对象
     */
    @Override
    public FinerSaleOrderDetail queryById(Integer Id) {
        return this.finerSaleOrderDetailDao.queryById(Id);
    }

    /**
     * 分页查询
     *
     * @param finerSaleOrderDetail 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FinerSaleOrderDetail> queryByPage(FinerSaleOrderDetail finerSaleOrderDetail, PageRequest pageRequest) {
        long total = this.finerSaleOrderDetailDao.count(finerSaleOrderDetail);
        return new PageImpl<>(this.finerSaleOrderDetailDao.queryAllByLimit(finerSaleOrderDetail, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finerSaleOrderDetail 实例对象
     * @return 实例对象
     */
    @Override
    public FinerSaleOrderDetail insert(FinerSaleOrderDetail finerSaleOrderDetail) {
        this.finerSaleOrderDetailDao.insert(finerSaleOrderDetail);
        return finerSaleOrderDetail;
    }

    /**
     * 修改数据
     *
     * @param finerSaleOrderDetail 实例对象
     * @return 实例对象
     */
    @Override
    public FinerSaleOrderDetail update(FinerSaleOrderDetail finerSaleOrderDetail) {
        this.finerSaleOrderDetailDao.update(finerSaleOrderDetail);
        return this.queryById(finerSaleOrderDetail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param Id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer Id) {
        return this.finerSaleOrderDetailDao.deleteById(Id) > 0;
    }
}
